<?php
/**
 * Created by PhpStorm.
 * User: xiong <1099446868@qq.com>
 * DateTime: 2018/11/16
 * TIME: 17:20
 */

namespace app\index\validate;


use think\facade\Request;

class ArticleValidate extends BaseValidate {

    protected $rule = [
        'title'=>'require',
        'tags'=>'require|checkTags',
        'content'=>'require',
        '__token__'=>'require|token'
    ];

    protected $message = [
        'tags.require'=>'标签必选,最多选择三个,推荐只选择一个',
        'tags.checkTags'=>'标签错误',
        'content.require'=>'文章内容必填',
        '__token__.require'=>'请复制文章内容后刷新本页面后重试',
        '__token__.token'=>'请复制文章内容后刷新本页面后重试',
    ];

    public function goCheck() {
        //获取http参数并验证
        $request = Request::instance();
        $param = $request->param();
        $param['content'] = $param['test-editormd-html-code'];
        unset($param['test-editormd-html-code']);
        $result = $this->batch()->check($param);
        if (!$result) {
            return [
                'istrue' => false,
                'msg'    => $this->getError()
            ];
        } else {
            return [
                'istrue' => true,
                'msg'    => '',
            ];
        }
    }

}